# 写入文件
import json

filename = 'programing.txt'
# 写入文件会清空原文件
with open(filename, 'w') as file_objet:
    file_objet.write("I love programing.\n")
    file_objet.write("I love creating new games.\n")

# 附加文件
with open(filename, 'a') as file_objet:
    file_objet.write("I also love finding meaning in large datasets..\n")
    file_objet.write("I creating apps that can run in a browser.\n")


filename = 'user.json'
user = {
    'name':'张三',
    'gender': 1,
    }
with open(filename, 'w') as file_objet:
    file_objet.write(json.dumps(user))

# 练习
filename = 'guest.txt'
user_name = input('what is your name?')
with open(filename, 'a') as file_object:
    file_object.write(user_name + '\n')

def guest_book():
    filename = 'guest_book.txt'
    hello = 'hi, hello'
    while True:
        guest_name = input('who is ?(enter q to exit)')
        if (guest_name == 'q'):
            break
        print(hello)
        with open(filename, 'a') as file_object:
            file_object.write(guest_name + ':' + hello + '\n')

guest_book()


